<?php
class InfoEditForm extends Form{
	function InfoEditForm(){
		Form::Form('InfoEditForm');
		
		if(!User::is_admin())
		Url::access_denied();
		
		AZLib::get_config();
	}
	
	function on_submit()
	{
		$content		=	Url::get('content');
		
		if(get_magic_quotes_gpc()){
			$content  	= stripslashes($content);
		}
		
		require_once ROOT_PATH.'includes/htmLawed.php';
		
		$config = array(
			'safe'=>1, // Dangerous elements and attributes thus not allowed
			'elements'=>'*', // All except table-related are OK
			'deny_attribute'=>'class, id' // None of the allowed elements can have these attributes
		);
		
		$spec = 'a = title, href;'; // The 'a' element can have only these attributes

		$content = htmLawed($content, $config, $spec);
		$content = AZLib::clean_value($content);
		
		$this->checkFormInput('Nội dung','content',$content,'str',true);
		
		if(!$this->errNum)
		{
			if(isset(CGlobal::$configs['Info_'.AZNet::$page['name']]))
				DB::update('configs',array("conf_val"=>$content),"conf_key='Info_".AZNet::$page['name']."'");
			else
				DB::insert('configs',array("conf_key"=>'Info_'.AZNet::$page['name'],"conf_val"=>$content));
			
			AZLib::get_config(0,1);
			
			Url::redirect_current();
		}
	}
	
	function draw(){
		global $display;
			
		$display->add("url_home",WEB_DIR);
		$display->add("title",AZNet::$page['title']);
		$display->add("url",Url::build_current());
		
		
		$content	=	stripslashes(Url::get('content'));
		
		if(!$content)
		{
			$content = stripslashes(@CGlobal::$configs["Info_".AZNet::$page['name']]['conf_val']);
		}
		
		$display->add("msg",$this->showFormErrorMessages(1));
		
		$display->add("content",$content);
		
		$this->beginForm();
		$display->output("InfoEdit");
		$this->endForm();
	}
}
?>